home *** CD-ROM | disk | FTP | other *** search
- #ifndef FWOBJREG_H
- #define FWOBJREG_H
- //========================================================================================
- //
- // File: FWObjReg.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // CLASS FW_CObjectRegistry
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CObjectRegistry
- {
- public:
-
- FW_CObjectRegistry();
- virtual ~FW_CObjectRegistry();
-
- typedef long ID;
-
- enum {kNotInRegistry = -1};
-
- virtual FW_CObjectRegistry::ID Register(const void *object) = 0;
- // Register an object and returns the (unique) ID
-
- virtual void Register(const void *object, FW_CObjectRegistry::ID id) = 0;
- // Register an object to particular id.
- // The id must not already be in the registry.
-
- virtual FW_CObjectRegistry::ID Lookup(const void *object) = 0;
- // Look up an object in the registry, return kNonInRegistry if object not found.
-
- virtual const void* Lookup(FW_CObjectRegistry::ID id) = 0;
- // Find an object by ID, return its pointer.
- // Return 0 if id not in registry.
- };
-
- //========================================================================================
- // CLASS FW_CBasicObjectRegistry
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CBasicObjectRegistry : public FW_CObjectRegistry
- {
- public:
-
- FW_CBasicObjectRegistry();
- virtual ~FW_CBasicObjectRegistry();
-
- virtual FW_CObjectRegistry::ID Register(const void *object);
- // Register an object and return its ID.
-
- virtual void Register(const void *object, FW_CObjectRegistry::ID id);
- // Register an object to particular id
-
- virtual FW_CObjectRegistry::ID Lookup(const void *object);
- // Look up an object in the registry, return kNonInRegistry if object not found.
-
- virtual const void* Lookup(FW_CObjectRegistry::ID id);
- // Find an object by ID, return its pointer.
- // Return 0 if id not in registry.
-
- private:
-
- void GrowList();
- // Grow the list by kExpansion slots
-
- struct SAssociation
- {
- FW_CObjectRegistry::ID fID; // object id
- const void* fObject; // object address
- };
-
- void InitAssociation(SAssociation& assoc)
- {
- assoc.fID = kNotInRegistry;
- assoc.fObject = 0;
- }
-
- enum {kExpansion = 8};
- SAssociation* fList;
- long fListLength;
- long fPhysicalListLength;
- FW_CObjectRegistry::ID fNextUnusedID;
-
- FW_CBasicObjectRegistry(const FW_CBasicObjectRegistry& readableStream);
- FW_CBasicObjectRegistry& operator=(const FW_CBasicObjectRegistry& registry);
- // Copy constructor and assignment operator not valid for this class.
- };
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-